# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=gc
pkgname=('libgc' 'libgc-devel')
pkgver=7.6.8
pkgrel=1
pkgdesc="A garbage collector for C and C++"
arch=('i686' 'x86_64')
groups=('libraries')
url="https://www.hboehm.info/gc/"
license=('GPL')
source=("https://github.com/ivmai/bdwgc/releases/download/v${pkgver}/${pkgbase}-${pkgver}.tar.gz"
        gc-7.6-msys2.patch
        gc_cpp_delete.patch)
makedepends=(libatomic_ops-devel)
options=('!libtool')
sha256sums=('040ac5cdbf1bebc7c8cd4928996bbae0c54497c151ea5639838fa0128102e258'
            'e926468756764b66c6c896d99b244bc27c310d4616b03c0c06dc613a23b3ac39'
            '26fb4c2cf0d44c26419ac51a5c95707febfc104ca932dafac3470e2b05241498')

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  patch -p1 -i ${srcdir}/gc-7.6-msys2.patch
  patch -p1 -i ${srcdir}/gc_cpp_delete.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  ../${pkgbase}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-cplusplus \
    --enable-threads=pthreads \
    --with-libatomic-ops=yes \
    --enable-handle-fork

  make
}

check() {
  cd "${srcdir}/build-${CARCH}"

  make check
}

package_libgc() {
  depends=('libatomic_ops' 'gcc-libs')
  cd "${srcdir}/build-${CARCH}"

  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}/usr/{include,lib}
}

package_libgc-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("libgc=${pkgver}" "libatomic_ops-devel")

  cd "${srcdir}/build-${CARCH}"

  make DESTDIR=${pkgdir} install

  rm -rf ${pkgdir}/usr/{bin,share}
}
